package com.cy.pj.goods.service;


import com.cy.pj.goods.dao.GoodsDao;
import com.cy.pj.goods.pojo.Goods;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService{//is a(在这种关系中父类或接口定义规范或共性)

    private  static final Logger log= LoggerFactory.getLogger(GoodsServiceImpl.class);
    @Autowired
    private GoodsDao goodsDao;//has a（一个好汉三个帮-强调的是协同-例如：陆海空，公检法）

    @Override
    public int updateGoods(Goods entity) {//use a（GoodsServiceImpl的方法中用到了integer，Goods）
        return goodsDao.updateGoods(entity);
    }

    @Override
    public Goods findById(Integer id) {
        return goodsDao.findById(id);//将来还可以将查询到的结果在业务逻辑层存储到cache
    }

    @Override
    public int saveGoods(Goods entity) {
        return goodsDao.insertGoods(entity);
    }

    @Override
    public int deleteById(Integer id) {
        return goodsDao.deleteById(id);
    }

    @Override
    public List<Goods> findGoods() {
        long t1=System.currentTimeMillis();
        List<Goods> list=goodsDao.findGoods();
        long t2=System.currentTimeMillis();
        log.info("findGoods time->{}", t2-t1);//{}为占位符
        return list;
    }
}
